package app 
{
	import app.textures.TextureInfo;
	import com.bit101.components.HBox;
	import fl.controls.Button;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	/**
	 * ...
	 * @author Dmitriy Gaiduk
	 */
	public class ModuleFacadeChoose extends Sprite
	{
		
		private var _appModel:AppModel;
		private var _buttons:Vector.<Button>;
		
		public function ModuleFacadeChoose(model:AppModel) 
		{
			_appModel = model;
			addEventListener(Event.ADDED_TO_STAGE, handleAddedToStage);
		}
		
		private function handleAddedToStage(e:Event):void 
		{
			removeEventListener(Event.ADDED_TO_STAGE, handleAddedToStage);
			initModule();
		}
		
		private function initModule():void 
		{
			_buttons = new Vector.<Button>();
			var btnBox:HBox = new HBox(this, 10, 10);
			for each(var texture:TextureInfo in _appModel.facadeTextures)
			{
				var btn:Button = new Button();
				btn.width = 100;
				btn.label = texture.name;
				btnBox.addChild(btn);
				_buttons.push(btn);
				btn.addEventListener(MouseEvent.CLICK, handleBtnClick);
			}
			
		}
		
		private function handleBtnClick(e:MouseEvent):void 
		{
			var index:int = _buttons.indexOf(e.currentTarget);
			if (index > -1)
			{
				
				//_appModel.currentFacadeTexture = index;
			}
		}
		
	}

}